/*
 * @Author: zwc 6537397+uni-yunApp@user.noreply.gitee.com
 * @Date: 2023-04-13 15:57:06
 * @LastEditors: zwc 6537397+uni-yunApp@user.noreply.gitee.com
 * @LastEditTime: 2023-04-13 16:54:05
 * @FilePath: \ant-design-vue-admin-master\src\store\modules\user.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { getUserInfo } from '@/api/user/user.js'
const user = {
  state: {
    userInfo: {},
    btnAuthor: []
  },
  getters: {
    userInfo: state => state.userInfo
  },
  mutations: {
    SET_USERINFO: (state, userInfo) => {
      state.userInfo = userInfo
    },
    SET_BTN_AUTHOR: (state, btnAuthor = []) => {
      const arr = []
      for (const item of btnAuthor) {
        arr.push(item.code)
      }
      state.btnAuthor = arr
    }
  },
  actions: {
    // 获取用户信息
    GetUserInfo ({ commit, state }) {
      return new Promise((resolve, reject) => {
        getUserInfo({ systemId: 'pw' }).then(res => {
          // console.log('用户接口', res)
          if (res) {
            commit('SET_USERINFO', res)
            commit('SET_BTN_AUTHOR', res.authorityResults)
            // commit('SET_STATUS', true)
            resolve(res)
          } else {
            this.$message.error('获取用户信息失败,请重新登录')
            setTimeout(() => {
              // window.location.href = process.env.VUE_APP_ISSO_LOGOUT_URL + window.location.href
            }, 2000)
          }
          // resolve(res)
        }).catch(error => {
          console.log(error)
          reject(error)
        })
      })
    }
  }
}
export default user
